import axios from 'axios'

const request = axios.create({
	timeout: 5000
})


request.interceptors.request.use(config => {
	config.headers.token = 'XXXXXXXXXXXXXXXXXXX'
	return config
}, err => {
	return Promise.reject(err)
})

request.interceptors.response.use(response => {
	const { code } = response.data

	if (code !== 200) {
		if (code === 500) {
			console.log('服务器有问题');
		}
		if (code === 404) {
			console.log('资源找不到');
		}
		if (code === 401) {
			console.log('权限有问题--token');
		}
		if (code === 501) {
			console.log('服务器有问题');
		}

	}
	return response
}, err => {
	return Promise.reject(err)
})


export default request